Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

retext-visit

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

retext-visit

Retext node visitor

  • 0.1.1
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

retext-visit Build Status Coverage Status

retext node visitor.

Installation

npm:

$ npm install retext-visit

Component:

$ component install wooorm/retext-visit

Bower:

$ bower install retext-visit

Usage

var Retext,
    retext,
    visit;

Retext = require('retext');
visit = require('retext-visit');

retext = new Retext().use(visit);

API

The below examples uses retext 0.2.0, which is currently in beta. For an example with the stable retext, see retext-visit@0.1.0.

Node#visit(function(Node): boolean?)

retext.parse('A simple English sentence.', function (err, tree) {
    if (err) throw err;

    /**
     * Visit every node in the first sentence.
     */

    tree.head.head.visit(function (node) {
        console.log(node.toString(), node.type);
    });
    /**
     * 'A', 'WordNode'
     * 'A', 'TextNode'
     * ' ', 'WhiteSpaceNode'
     * ' ', 'TextNode'
     * 'simple', 'WordNode'
     * 'simple', 'TextNode'
     * ' ', 'WhiteSpaceNode'
     * ' ', 'TextNode'
     * 'English', 'WordNode'
     * 'English', 'TextNode'
     * ' ', 'WhiteSpaceNode'
     * ' ', 'TextNode'
     * 'sentence', 'WordNode'
     * 'sentence', 'TextNode'
     * '.', 'PunctuationNode'
     * '.', 'TextNode'
     */
});

Invoke callback for every descendant of the operated on context.

  • callback (function(Node): boolean?): Visitor. Stops visiting when the return value is false.

Node#visitType(type, callback)

retext.parse('A simple English sentence.', function (err, tree) {
    if (err) throw err;

    /**
     * Visit every word node.
     */

    tree.visitType(tree.WORD_NODE, function (node) {
        console.log(node.toString(), node.type);
    });
    /**
     * 'A', 'WordNode'
     * 'simple', 'WordNode'
     * 'English', 'WordNode'
     * 'sentence', 'WordNode'
     */
});

Invoke callback for every descendant with a given type in the operated on context.

  • type (string): Type of the nodes to visit.
  • callback (function(Node): boolean?): Visitor. Stops visiting when the return value is false.

License

MIT © Titus Wormer

Keywords

FAQs

Package last updated on 22 Sep 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc